package com.winit.openapi.wh.controller;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.fastjson.JSONObject;
import com.winit.common.spi.context.CommandContext;
import com.winit.oms.spi.inbound.InboundOrderSLAService;
import com.winit.oms.spi.inbound.command.InboundOrderSLACommand;
import com.winit.openapi.constants.ErrorCode;
import com.winit.openapi.controller.BaseController;
import com.winit.openapi.exception.ApiException;
import com.winit.openapi.model.RequestMsg;
import com.winit.openapi.model.ResponseMsg;
import com.winit.openapi.util.ValidateUtil;


@Controller
@RequestMapping(value = "/wh/inboundOrderSLA")
public class InboundOrderSLAController extends BaseController {

    @Resource
    private InboundOrderSLAService inboundOrderSLAService;
    

    @RequestMapping(value = "/calExpectedShelve")
    public String calExpectedShelve(@ModelAttribute RequestMsg requestMsg, @ModelAttribute ResponseMsg responseMsg) {
        Object obj = requestMsg.getData();
        String orderNo =null;
        Long logisticsPlanId=null;
        if (obj instanceof JSONObject) {
            JSONObject json = (JSONObject) obj;
            ValidateUtil.validNotNull(json, "orderNo");
            ValidateUtil.validNotNull(json, "logisticsPlanId");
            orderNo = json.getString("orderNo");
            logisticsPlanId = json.getLong("logisticsPlanId");
        } else {
            throw new ApiException(ErrorCode.FIELD_TYPE_ERROR, "data");
        }
        // 查询订单详情
        InboundOrderSLACommand command = new InboundOrderSLACommand();
        command.setCtx(CommandContext.getContext());
        command.setOrderNo(orderNo);
        command.setLogisticsPlanId(logisticsPlanId);
        Date date = inboundOrderSLAService.calExpectedShelve(command);
        Map<String, Object> map =new HashMap<String, Object>();
        map.put("shelveCompletedDate", date);
        responseMsg.setData(date);
        return SUCCESS;
    }
}
